<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MVCWeb.Models.News>>" %>

<%@ Register Src="~/Views/Menu/MainMenu.ascx" TagName="MainMenu" TagPrefix="mmuc" %>

<%@ Register Src="~/Views/Shared/LogOnUserControl.ascx" TagName="LogOnUserControl" TagPrefix="louc" %>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
    <title>Admin:
        <%= System.Configuration.ConfigurationManager.AppSettings["SiteName2"] %>'s News</title>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">

    <script language="javascript" type="text/javascript">
        function ChangeStatus(id, name, status) {
            var s = 'active';
            if (status.toString() == "True") {
                s = 'deactive';
            }
            if (confirm("Are you sure that this news: " + name + " will be " + s + "?")) {
                // Perform change status.
                var action = '<%= Url.Action("ChangeStatus", "News") %>/' + id;
                var request = new Sys.Net.WebRequest();
                request.set_httpVerb("POST");
                request.set_url(action);
                request.add_completed(ChangeStatusCompleted);
                request.invoke();
            }
        }

        function ChangeStatusCompleted() {
            // Reload page  
            window.location.reload();
        }    
    </script>

    <louc:LogOnUserControl ID="LogOnUserControl1" runat="server" />
    <!-- BEGIN: MainMenu -->
    <mmuc:MainMenu ID="MainMenu1" runat="server" />
    <!-- END: MainMenu -->
    <h2>
        Admin:
        <%= System.Configuration.ConfigurationManager.AppSettings["SiteName2"] %>'s News
    </h2>
    <hr />
    <% foreach (var item in Model)
       { %>
    <table cellpadding="4" cellspacing="1" border="0" width="100%">
        <tr>
            <td valign="top">
                <a href='<%= Url.Action("Edit", "News", new { id = item.NewsId })%>'>Edit </a>
            </td>
            <td valign="top">
                <a onclick="ChangeStatus(<%=item.NewsId%>, '<%=item.Title%>', '<%=item.Active%>')" href="JavaScript:void(0)">
                    <%
                        if (item.Active)
                        {
                    %>
                    Active
                    <%
                        }
                        else
                        {%>
                    Deactive
                    <%
                        }%>
                </a>
            </td>
            <td valign="top" style="width: 1%" colspan="2">
                <% if (!string.IsNullOrEmpty(item.ImageUrl))
                   { %>
                <img width="200px" alt="" visible='<%= item.ImageUrl.Length > 0 %>' src='<%= item.ImageUrl %>' />
                <%} %>
            </td>
            <td style="width: 100%" valign="top">
                <a class="title" target="_blank" href=''>
                    <%= HttpUtility.HtmlDecode(item.Title) %></a>
                <div style="padding-top: 2px">
                </div>
                Date:
                <%= item.PublishedDate.ToShortDateString() %>
                <div style="padding-top: 2px"></div>
                    <%= HttpUtility.HtmlDecode(item.SubTitle) %>
            </td>
        </tr>
    </table>
    <br />
    <hr />
    <br />
    <% } %>
    <p>
        <%= Html.ActionLink("Create community news", "Create", new {communityId=Request.QueryString["CommunityId"]})%>
        |
        <%= Html.ActionLink("Create site news", "CreateLeisureLifeNews", new {communityId=Request.QueryString["CommunityId"]})%>
    </p>
</asp:Content>
